import Vue from "vue";
import VueRouter from "vue-router";
import LoginView from "@/views/login/LoginView.vue";
import RegisterView from "@/views/login/RegisterView.vue";
import HomeView from "@/views/admin/HomeView.vue";
import SidebarSettings from "@/views/dash/SidebarSettings.vue";
import indexView from "@/views/dash/IndexView.vue";
import CommodityCategory from "@/views/product/category/CommodityCategory.vue";
import ProductList from "@/views/product/list/ProductList.vue";
import OrderList from "@/views/order/OrderList.vue";
import RoleManagement from "@/views/role/RoleManagement.vue";
import UserList from "@/views/dash/UserList.vue";
import ProductCreate from "@/views/product/create/ProductCreateView.vue";
import ActionList from "@/views/dash/ActionList.vue";
import PermissionList from "@/views/dash/PermissionList.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    component: LoginView,
    meta: {
      title: "登录",
    },
  },
  {
    path: "/register",
    component: RegisterView,
  },
  {
    component: HomeView,
    redirect: "/index",
    path: "/",
    children: [
      {
        path: "/index",
        component: indexView,
        meta: {
          title: "首页",
        },
      },
    ],
  },
  {
    path: "/product",
    component: HomeView,
    redirect: "/product/category",
    meta: {
      title: "商品管理",
    },
    children: [
      {
        path: "/product/category",
        component: CommodityCategory,
        meta: {
          title: "商品类别",
        },
      },
      {
        path: "/product/list",
        component: ProductList,
        meta: {
          title: "商品列表",
        },
      },
      {
        path: "/product/create",
        component: ProductCreate,
        meta: {
          title: "创建商品",
        },
      },
    ],
  },
  {
    path: "/user",
    component: HomeView,
    redirect: "/user/list",
    meta: {
      title: "用户管理",
    },
    children: [
      {
        path: "/user/list",
        component: UserList,
        meta: {
          title: "用户列表",
        },
      },
    ],
  },
  {
    path: "/permission",
    component: HomeView,
    redirect: "/permission/roles",
    meta: {
      title: "权限管理",
    },
    children: [
      {
        path: "/permission/roles",
        component: RoleManagement,
        meta: {
          title: "角色管理",
        },
      },
      {
        path: "/permission/list",
        component: PermissionList,
        meta: {
          title: "权限列表",
        },
      },
    ],
  },
  {
    path: "/order",
    component: HomeView,
    redirect: "/order/list",
    meta: {
      title: "订单管理",
    },
    children: [
      {
        path: "/order/list",
        component: OrderList,
        meta: {
          title: "订单列表",
        },
      },
    ],
  },
  {
    path: "/site",
    component: HomeView,
    redirect: "site/aside",
    meta: {
      title: "网站设置",
    },
    children: [
      {
        path: "/site/aside",
        component: SidebarSettings,
        meta: {
          title: "侧边栏设置",
        },
      },
      {
        path: "/site/action",
        component: ActionList,
        meta: {
          title: "操作记录",
        },
      },
    ],
  },
];

const router = new VueRouter({
  routes,
});

export default router;
